package ro.upt.dcda.pricezone.s1.requests;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;

import ro.upt.dcda.pricezone.common.ConnectionFactory;
import ro.upt.dcda.pricezone.s1.pojo.User;

public class RegisterRequest {

	public boolean work(String name, String email, String password) {
		Session session = ConnectionFactory.getFactory().openSession();
		Transaction tx = null;
		User newUser = new User(email, name, password);
		try {
			tx = session.beginTransaction();
			session.save(newUser);
			tx.commit();
		} catch (HibernateException e) {
			if (tx != null)
				tx.rollback();
			e.printStackTrace();
			return false;
		} finally {
			session.close();
		}
		return true;
	}
}
